<?php

require_once("../../inc/magmi_defs.php");
require_once("../inc/magmi_datapump.php");

/** Define a logger class that will receive all magmi logs * */
class TestLogger
{

    /**
     * logging methos
     * @param string $data : log content
     * @param string $type : log type
     */
    public function log($data, $type)
    {
        //echo "$type:$data\n";
    }

}

/**
 * create a Product import Datapump using Magmi_DatapumpFactory
 */
$dp = Magmi_DataPumpFactory::getDataPumpInstance("productimport");
/**
 * Start import session
 * with :
 * - profile : test_ptj
 * - mode : create
 * - logger :  an instance of the class defined above
 */
/**
 * FOR THE SAMPLE TO WORK CORRECTLY , YOU HAVE TO DEFINE A test_ptj profile with :
 * UPSELL/CROSS SELL, ITEM RELATER, CATEGORIES IMPORTER/CREATOR selected
 * ON THE FLY INDEXER IS RECOMMENDED (better endimport performance)
 * Reindexer needed also to have products show up on front : select all but "catalog_category_product" & "url_rewrite" (both are handled by on the fly indexer)
 */
/* Create 5000 items , with  every 100 :
 * 
 * 	upsell on last 100 even
 *     cross sell on last 100 odd 
 *     related on last 100 every 5
 *     cross sell on last 100 every 10 
 *     categories named catX/even or catX/odd with X is thousand of item (using categories plugin) */
if ($_REQUEST['sky'])
{
    $dp->beginImportSession("default", "create", new TestLogger());
    $item = array();
    $item["store"] = $_REQUEST["store"];
    $item["type"] = $_REQUEST["type"];
    $item["sku"] = $_REQUEST["sku"];
    $item["name"] = $_REQUEST["name"];
    $item["description"] = $_REQUEST["description"];
    $item["attribute_set"] = $_REQUEST["attribute_set"];
    $item["categories"] = $_REQUEST["categories"];
    $item["price"] = $_REQUEST["price"];
    $item["cost"] = $_REQUEST["cost"];
    $item["manufacturer"] = $_REQUEST["manufacturer"];
    $item["description"] = $_REQUEST["description"];
    $item["image"]= $_REQUEST["image"];
    $item["small_image"] = $_REQUEST["small_image"];
    $item["thumbnail"] = $_REQUEST["thumbnail"];
    $item["gallery"] = $_REQUEST["gallery"];
    $dp->ingest($item);
    $dp->endImportSession();
}
/* end import session, will run post import plugins */

//end

echo "success";